package com.hh.game.service.gateway.webscoket.handler;

import com.hh.game.service.gateway.codec.websocket.OutputMessage;
import com.hh.game.service.gateway.codec.websocket.WebSocketResponse;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;

import java.util.List;

public class ResponseToMessageEncoder extends MessageToMessageEncoder<WebSocketResponse> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, WebSocketResponse response, List list) throws Exception {
        OutputMessage msg = response.getOutputMessage();
        ByteBuf buf = msg.getByteBuf();
        list.add(new BinaryWebSocketFrame(buf));
    }
}
